require "import"
import "tools"
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS).setStatusBarColor(0xff4DB6AC)
activity.setContentView("aConcat_")
concat.background=btBackground
oDir.text=LUA_SD.."/avHandle/output/"
item= {
  LinearLayout;
  layout_width="-1";
  layout_height="50dp";
  gravity="center|left";
  {
    TextView;
    layout_marginLeft="50dp";
    id="dir";
    text="路径";
  };
};
adapter=LuaAdapter(activity,item)
adapter.add{dir="点击添加音频文件"}
lv.Adapter=adapter
lv.onItemClick=function(a,b,c,d)
  local s= b.Tag.dir.text
  if s=="点击添加音频文件"
    ChoiceFile(LUA_SD,function(p)
      table.insert(adapter.data,#adapter.data,{dir=p})
      adapter.notifyDataSetChanged()
    end)
   else
    local items={"删除","预览","上移","下移"}
    AlertDialog.Builder(this) .setItems(items,{onClick=function(l,v)
        local str=items[v+1]
        if str=="删除"
          table.remove(adapter.data,d)
          adapter.notifyDataSetChanged()
        end
        if str=="预览"
          dialogPlayer(s)
        end

        if str=="上移"
          local data =adapter.data[d]
          if d-1>0
            table.remove(adapter.data,d)
            table.insert(adapter.data,d-1,data)
            adapter.notifyDataSetChanged()
           else
            print("最上边了")
          end
        end
        if str=="下移"
          local data =adapter.data[d]
          if d+2<=#adapter.data
            table.remove(adapter.data,d)
            table.insert(adapter.data,d+1,data)
            adapter.notifyDataSetChanged()
           else
            print("最下边了")
          end
        end
    end}).show()
  end
end
concat. onClick=function()
  local t,t1={},{}
  if #adapter.data>1
    for n=1,#adapter.data-1
      table.insert(t,adapter.data[n].dir)
    end
    local concat=""
    for n=1,#t
      table.insert(t1, "-i "..t[n].." "..LUA_SD.."/avHandle/tmp/".. tostring(n)..".aac")
      local sep=""
      if concat~=""
        sep="|"
      end
      concat=concat..sep..LUA_SD.."/avHandle/tmp/".. tostring(n)..".aac"
    end
    if filename.text~=""
      table.insert(t1,#t1+1, [[-i concat:]]..concat..[[ -y -acodec copy ]]..oDir.text..filename.text..[[.aac]])
      activity.newActivity("handle",t1)
     else
      print("请输入输出文件名")
    end
   else
    print("请选择音频文件")
  end
end